/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ttnet.configuration;

import java.io.IOException;
import java.io.InputStream;
import java.io.Serializable;
import java.util.Calendar;
import java.util.jar.Attributes;
import java.util.jar.Manifest;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import javax.servlet.ServletContext;

import org.apache.log4j.Logger;

/**
 * @author serhan.tuygun '
 */
@ManagedBean(name = "version")
@SessionScoped
public class Version implements Serializable {

	private static final Logger LOG = Logger.getLogger(Version.class);

	private String specificationVersion;
	private String specificationTitle;
	private String buildNumber;
	private String buildId;
	private String buildBy;
	private String currentYear;

	public Version() {
		ServletContext servletContext = (ServletContext) FacesContext
				.getCurrentInstance().getExternalContext().getContext();
		InputStream input = servletContext
				.getResourceAsStream("/META-INF/MANIFEST.MF");

		Manifest mf;
		try {
			mf = new Manifest(input);
			Attributes atts = mf.getMainAttributes();
			specificationVersion = atts.getValue("Specification-Version");
			specificationTitle = atts.getValue("Specification-Title");
			buildNumber = atts.getValue("Build-Number");
			buildBy = atts.getValue("Built-By");
			buildId = atts.getValue("Build-Id");
			specificationVersion = atts.getValue("Specification-Version");
		} catch (IOException e) {
			LOG.error(e, e);
		}

		currentYear = Calendar.getInstance().get(Calendar.YEAR) + "";
	}

	public String getSpecificationVersion() {
		return specificationVersion;
	}

	public void setSpecificationVersion(String specificationVersion) {
		this.specificationVersion = specificationVersion;
	}

	public String getSpecificationTitle() {
		return specificationTitle;
	}

	public void setSpecificationTitle(String specificationTitle) {
		this.specificationTitle = specificationTitle;
	}

	public String getBuildNumber() {
		return buildNumber;
	}

	public void setBuildNumber(String buildNumber) {
		this.buildNumber = buildNumber;
	}

	public String getBuildId() {
		return buildId;
	}

	public void setBuildId(String buildId) {
		this.buildId = buildId;
	}

	public String getBuildBy() {
		return buildBy;
	}

	public void setBuildBy(String buildBy) {
		this.buildBy = buildBy;
	}

	public void setCurrentYear(String currentYear) {
		this.currentYear = currentYear;
	}

	public String getCurrentYear() {
		return currentYear;
	}
}
